// 权限
import { constantRoutes, asyncRoutes } from '@/router/index.js'
export default {
  namespaced: true,
  state: {
    routes: constantRoutes // 静态路由
  },
  mutations: {
    // 存储动态路由
    setRoutes(state, routes) {
      state.routes = [...constantRoutes, ...routes]
    },
    // 删除路由
    removeRoutes(state) {
      state.routes = constantRoutes
    }
  },
  actions: {
    fiterRoutes(context, menus) {
      // 进行对路由的筛选拿到有权限的动态路由
      const filterRoutes = asyncRoutes.filter(item => {
        return menus.includes(item.children[0].name)
      })
      context.commit('setRoutes', filterRoutes)
      return filterRoutes
    }
  }
}
